package com.atguigu.gulimall.coupon.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.gulimall.coupon.entity.CouponEntity;
import com.atguigu.gulimall.coupon.service.CouponService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;



/**
 * ÓÅ»ÝÈ¯ÐÅÏ¢
 *
 * @author guokefa
 * @email guokefa@gmail.com
 * @date 2022-02-10 11:17:26
 */
@RefreshScope //刷新配置
@RestController
@RequestMapping("coupon/coupon")
public class CouponController {
    @Autowired
    private CouponService couponService;

    @Value("${coupon.user.name}")
    protected String name;

    @Value("${coupon.user.age}")
    protected Integer age;

    static Map<Integer,Object> mapList = new HashMap<>();
    static Integer id=0;

    @RequestMapping("test")
    public R test(@RequestParam(value = "uid",required = false,defaultValue = "1") Integer uid,
                  @RequestParam(value = "step",required = false,defaultValue = "2") Integer step)
    {


        return R.ok().put("name",name).put("age",age);

//        System.out.println(uid);
//        System.out.println(step);
//        mapList.put(uid,step);
//
//        return R.ok().put("map",mapList);
//        Integer integer = id++;
//        System.out.println(id);
////        ArrayList<String> objects = new ArrayList<>();
////        objects.add(str);
//        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
//        objectObjectHashMap.put("uid",params.str);
//
//        //Map<Integer,Object> mapList = new HashMap();
//        mapList.put(integer,objectObjectHashMap);
//       // CouponController.mapList = mapList;
//
//        //CouponController.mapList.put(integer,objects);
//
//        return R.ok().put("test", mapList);
    }

    @RequestMapping("member/list")
    public R memberCoupon(){
        CouponEntity couponEntity = new CouponEntity();
        couponEntity.setCouponName("满2件减10元");


        return R.ok().put("coupon",couponEntity);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("coupon:coupon:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("coupon:coupon:info")
    public R info(@PathVariable("id") Long id){
		CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("coupon:coupon:save")
    public R save(@RequestBody CouponEntity coupon){
		couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("coupon:coupon:update")
    public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("coupon:coupon:delete")
    public R delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
